﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PocketGPW
{
    public partial class SettingsEditor : Form
    {
        private class Setting
        {
            // zostaw public
            public string Text
            {
                get;
                set;
            }

            // zostaw public
            public int Value
            {
                get;
                set;
            }
        }   

        public SettingsEditor()
        {
            InitializeComponent();

            Icon = Properties.Resources.Icon;
        }

        private void _miOk_Click(object sender, EventArgs e)
        {
            SettingsHelper.Set(SettingsHelper.Keys.Refresh, ((Setting)_cbRefresh.SelectedItem).Value);
            SettingsHelper.Set(SettingsHelper.Keys.Notifications, _cbNotifications.Checked);

            Close();
        }

        private void _miCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void SettingsEditor_Load(object sender, EventArgs e)
        {
            FillRefresh();

            SetRefresh();
            SetNotifications();
        }

        private void FillRefresh()
        {
            List<Setting> refreshList = new List<Setting>();
            refreshList.Add(new Setting() { Text = "Wyłączone", Value = 0 });
            refreshList.Add(new Setting() { Text = "Minuta", Value = 1 });
            refreshList.Add(new Setting() { Text = "2 minuty", Value = 2 });
            refreshList.Add(new Setting() { Text = "5 minut", Value = 5 });
            refreshList.Add(new Setting() { Text = "10 minut", Value = 10 });
            refreshList.Add(new Setting() { Text = "20 minut", Value = 20 });
            refreshList.Add(new Setting() { Text = "Godzina", Value = 60 });

            // ustawienia pod kolekcje
            _cbRefresh.ValueMember = "Value";
            _cbRefresh.DisplayMember = "Text";

            // załaduj kolekcje
            _cbRefresh.DataSource = refreshList;
        }

        private void SetRefresh()
        {
            int r = SettingsHelper.GetInt32(SettingsHelper.Keys.Refresh);
            for (int i = 0; i < _cbRefresh.Items.Count; i++)
            {
                if (r == ((Setting)_cbRefresh.Items[i]).Value)
                {
                    _cbRefresh.SelectedIndex = i;
                    break;
                }
            }
        }

        private void SetNotifications()
        {
            _cbNotifications.Checked = SettingsHelper.GetBoolean(SettingsHelper.Keys.Notifications);
        }
    }
}